package com.likou.written.hengsheng;

import java.util.Scanner;

/**
 * Author: 陈桂明
 * Date: 2025/10/10 20:42
 * Description: hengsheng2
 */
public class hengsheng2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // while (in.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }

        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            long sum = 1L;
            for (int j = i; j < n; j++) {
                sum *= nums[j];
                if (isWQ(sum)) {
                    ans = Math.max(ans, j - i + 1);
                }
            }

        }

        if (ans == 0) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
    }

    private static boolean isWQ(long num) {
        long mid = num / 2;
        for (int i = 1; i <= mid; i++) {
            if ((long) i * i == num) {
                return true;
            }
        }

        return false;
    }
}
